$(function () {
    //图片预览
    $('#inputCover').on('change', function () {

        if (this.files[0] != undefined) {
            let url = URL.createObjectURL(this.files[0]);
            console.log(this.files[0]);
            console.log(this.files[0].name);
            $('.article_cover').attr('src', url)
        }
    });
    // 日期
    jeDate('#indate', {
        format: "YYYY-MM-DD",
        minDate: "1900-01-01 00:00:00",
        //最小日期 或者 "1900-01-01" 或者 "10:30:25"
        maxDate: "2099-12-31 23:59:59",
        zIndex: 22099,
    });
    // 富文本框
    let E = window.wangEditor;
    let editor = new E('.editor');
    editor.create();

    //文章类别
    $.ajax({
        type: 'get',
        url: BigNew.category_list,
        success(backData) {
            if (backData.code == 200) {
                let resHtml = template('categoryTemp', backData);
                $('.category').html(resHtml)
            };
        },
    });


    function getArticle(state, msg) {
        let data = new FormData($('#form')[0]);
        data.append('content', editor.txt.html());
        data.append('state', state);
        $.ajax({
            type: 'post',
            url: BigNew.article_publish,
            data,
            contentType: false,
            processData: false,
            success(backData) {
                if (backData.code == 200) {
                    console.log(backData);
                    alert(msg);
                    window.location.href = './article_list.html'
                };
            },
        });
    }
    // 发布文章
    $('.btn-release').click(function (e) {
        e.preventDefault();
        getArticle('已发布', '发布成功');

    });
    // 存为草稿
    $('.btn-draft').click(function (e) {
        e.preventDefault();
        getArticle('草稿', '已存为草稿')


    })
});